//
//  MineViewController.m
//  ITrip
//
//  Created by dlios on 15-5-21.
//  Copyright (c) 2015年 lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "MineViewController.h"
#import "SetViewController.h"
#import "CollectViewController.h"
#import <SDImageCache.h>
#import <UMFeedback.h>
#import "AboutViewController.h"

#define USERDEFAULT [NSUserDefaults standardUserDefaults]

@interface MineViewController ()<UITableViewDataSource, UITableViewDelegate>
{
    UITableView *MineTableView;
}
@property(nonatomic, retain) UILabel *label;
@end

@implementation MineViewController



- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    MineTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, self.view.frame.size.width * 220 / 375, self.view.frame.size.width, self.view.frame.size.height) style:UITableViewStylePlain];
    MineTableView.delegate = self;
    MineTableView.dataSource = self;
    [self.view addSubview:MineTableView];
    [MineTableView release];
    MineTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    UILabel *title = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 110, 30)];
    title.text = @"  我     的";
    title.font = [UIFont systemFontOfSize:20];
    title.font = [UIFont boldSystemFontOfSize:25];
    title.textColor = [UIColor whiteColor];
    self.navigationItem.titleView = title;
    
    
    UIImageView *titleView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.width * 220 / 375)];
    [self.view addSubview:titleView];
    titleView.backgroundColor = [UIColor yellowColor];
    [titleView setImage:[UIImage imageNamed:@"aboutUs"]];
    MineTableView.scrollEnabled = NO;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *identifier = @"cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
    }
    if (indexPath.section == 0) {
        cell.textLabel.text = @"清除缓存";
        NSInteger size = [[SDImageCache sharedImageCache] getSize];
        self.label = [[[UILabel alloc] initWithFrame:CGRectMake(0, 0, 70, 50)] autorelease];
        self.label.text = [NSString stringWithFormat:@"%ld MB", size / (1024 * 1024)];
        cell.accessoryView = self.label;
    } else if (indexPath.section == 1) {
        cell.textLabel.text = @"我的收藏";
    } else if (indexPath.section == 3) {
        cell.textLabel.text = @"关于我们";
    } else if (indexPath.section == 2) {
        cell.textLabel.text = @"意见反馈";
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        NSInteger size = [[SDImageCache sharedImageCache] getSize];
        [[SDImageCache sharedImageCache] clearDisk];
        self.label.text = [NSString stringWithFormat:@"%ld MB", size / (1024 * 1024)];
        [MineTableView reloadData];
    } else if (indexPath.section == 1) {
        CollectViewController *collect = [[CollectViewController alloc] init];
        [self.navigationController pushViewController:collect animated:YES];
        self.tabBarController.tabBar.hidden = YES;
        self.tabBarController.tabBar.translucent = YES;
    } else if (indexPath.section == 2) {
        [self presentModalViewController:[UMFeedback feedbackModalViewController]
                                animated:YES];
    } else if (indexPath.section == 3) {
        AboutViewController *about = [[AboutViewController alloc] init];
        [self.navigationController pushViewController:about animated:YES];
        self.tabBarController.tabBar.hidden = YES;
        self.tabBarController.tabBar.translucent = YES;
    }
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 5;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 40;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (section == 4) {
        return 600;
    }
    if (section != 3) {
        return 5;
    }
    return 30;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
